/*
                  InterfaceMenu Class Implementation
*/
#include "InterfaceMenu.h"

InterfaceMenu::InterfaceMenu()
{

}

InterfaceMenu::~InterfaceMenu()
{

}

int InterfaceMenu::Initialise()
{
    frmMenu = new Frame;
    frmMenu->Initialise(Point(0, 0), 1, 1);
    frmMenu->setBackground("data//interface//menu//menuframe.png");
    frmMenu->setVisible(true);
    frmMenu->setFixed(true);
    frmMenu->WindowAlign(ALIGN_CENTER, GetWindowSize());
    frmMenu->setPosition(Point((int)frmMenu->getPosition().x, 200));

    btnLocalGame = new Button;
    btnLocalGame->Initialise(Point(23, 150), "", "data//fonts//gui.ttf", 18, "data//interface//menu//localgame.png", "data//interface//menu//localgame_c.png", GetSDLColor(0, 0, 0));

    btnNetworkGame = new Button;
    btnNetworkGame->Initialise(Point(23, 210), "", "data//fonts//gui.ttf", 18, "data//interface//menu//networkgame.png", "data//interface//menu//networkgame_c.png", GetSDLColor(0, 0, 0));

    btnOptions = new Button;
    btnOptions->Initialise(Point(23, 270), "", "data//fonts//gui.ttf", 18, "data//interface//menu//options.png", "data//interface///menu//options_c.png", GetSDLColor(0, 0, 0));

    btnCredits = new Button;
    btnCredits->Initialise(Point(23, 330), "", "data//fonts//gui.ttf", 18, "data//interface//menu//credits.png", "data//interface//menu//credits_c.png", GetSDLColor(0, 0, 0));

    btnExit = new Button;
    btnExit->Initialise(Point(23, 390), "", "data//fonts//gui.ttf", 18, "data//interface//menu//exit.png", "data//interface//menu//exit_c.png", GetSDLColor(0, 0, 0));

    frmMenu->AddWidget(btnLocalGame, "btnLocalGame");
    frmMenu->AddWidget(btnNetworkGame, "btnNetworkGame");
    frmMenu->AddWidget(btnOptions, "btnOptions");
    frmMenu->AddWidget(btnCredits, "btnCredits");
    frmMenu->AddWidget(btnExit, "btnExit");

    frmgMenu.AddFrame(frmMenu, "frmgMenu");

    imgLogo.Initialise("data//interface//logo.png", Point((ConfigFile::iCurrentWindowResX / 2) - 350, -85));

    imgBackground.Initialise(ConfigFile::strBGPath, Point(0, 0));

    return 0;
}

InterfaceType InterfaceMenu::HandleInput(const SDL_Event& event)
{
    frmgMenu.parseInput(event);

    return CheckWidgetEvents();
}

int InterfaceMenu::Draw(SDL_Surface *surface)
{
    imgBackground.BlitToSurface(surface);
    imgLogo.BlitToSurface(surface);
    frmgMenu.BlitToSurface(surface);

    return 0;
}

InterfaceType InterfaceMenu::CheckWidgetEvents()
{
    GUIEvent guievent;

    while (frmMenu->PollEvent(guievent) == 0)
    {
        switch (guievent.getEventType())
        {
            case GUIEVENT_LEFTMOUSEUP:
            {
                if (guievent.getSource() == "btnExit")
                {
                    return EXIT;
                }

                if (guievent.getSource() == "btnLocalGame")
                {
                    return LOCALGAMELOBBY;
                }

                if (guievent.getSource() == "btnNetworkGame")
                {
                    return NETWORKMENU;
                }

                if (guievent.getSource() == "btnOptions")
                {
                    return OPTIONS;
                }

                if (guievent.getSource() == "btnCredits")
                {
                    return CREDITS;
                }
            }
            break;
        }
    }

    return NONE;
}
